<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap">
				</div>
				<div class="flex-end-center-wrap">
					<jk-select v-model="searchParams.typeCode" clearable value-key-name="code" :option-list="processList" placeholder="废棉类型" class="search-bar-item-size2 margin-5-0 item-gap"></jk-select>
					<div class="search-bar-item-size2 item-gap">
						<el-date-picker v-model="searchParams.yearMonth" :picker-options="pickerOptions" :clearable="false" size="small" style="width: 100%;" type="month" value-format="yyyy-MM" placeholder="月" />
					</div>
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table
				ref="jkTable"
				border
				:loading="tableLoading"
				:data="tableData"
				:height="tableHeight + 20"
			>
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<span v-if="item.keyName === 'rangeVal'">{{ formatRange(scope.row.minStandard, scope.row.maxStandard) }}</span>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>

			<!-- 分页组件 -->
			<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>
		</jk-card>
	</div>
</template>

<script>
    import calHeight from '@/mixins/cal-table-height';
    import { pageConfig, formatMonth } from '@/utils/jk/jk-tool';
    import getMenuColumn from '@/mixins/getMenuColumn';
    import handlerCache from '@/mixins/handler-cache';
    import { getMonthPageMaterialWeigh } from '@/api/production/reports';
    export default {
        name: 'WasteCottonReport',
        mixins: [calHeight, getMenuColumn, handlerCache],
        data() {
            return {
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    }
                },
                apiItem: {
                    'page': getMonthPageMaterialWeigh
                },
                detailDialogState: false,
                workshopList: [],
                tableLoading: true,
                tableData: [],
                totalCount: 0,
                processList: [{
                    code: 'XJL',
                    name: '下脚料'
                }, {
                    code: 'HH',
                    name: '回花'
                }],
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    yearMonth: undefined,
                    typeCode: undefined
                },
                noCalKey: ['belongDate', 'machineName'],
                dataItem: {}
            };
        },
        methods: {
            formatRange(minVal, maxVal) {
                if (minVal === 0 && maxVal === 0) {
                    return '/';
                }
                if (minVal === maxVal) {
                    return String(minVal);
                }
                return minVal + ' ~ ' + maxVal;
            },
            onVisibleChangeOfDetailDialogState(e) {
                this.detailDialogState = e;
            },
            // onDetailBtn(row, title) {
            //     const name = title.split('-').length ? title.split('-')[0] : '';
            //     const processConf = {
            //         '梳棉': 'SM',
            //         '末并': 'MB',
            //         '粗纱': 'CS',
            //         '细纱': 'XS',
            //         '自络': 'LT',
            //         '并线': 'BX',
            //         '倍捻': 'BN',
            //         '打包': 'DB'
            //     };
            //     this.dataItem = {
            //         typeCode: processConf[name] || '',
            //         belongDate: row.belongDate
            //     };
            //     this.detailDialogState = true;
            // },

            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            async getDependentData() {
                this.$set(this.searchParams, 'yearMonth', formatMonth(Date.now()));
                this.tableLoading = true;
                await this.getMenuColumnListRequest();
                await this.getListRequest();
                this.tableLoading = false;
            },
            /** 查询列表 */
            getListRequest() {
                this.tableLoading = true;
                const params = { ...this.searchParams };
                // params.yearMonth = params.yearMonth.replace('-', '');
                // if (params.yearMonth) {
                //     params.year = new Date(params.yearMonth).getFullYear();
                //     params.month = new Date(params.yearMonth).getMonth() + 1;
                // }
                return this.apiItem['page'](params).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                        this.totalCount = res.data.count;
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.totalCount = 1;
                this.getListRequest();
            }
        },
        mounted() {
            this.getDependentData();
        }
    };
</script>
<style>
</style>
